package com.sqy.Test;

import com.sqy.read.ReadTxt;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.*;

public class test {
    public static void main(String[] args) throws Exception {
        String path = "E:\\.学习\\2022秋季学期\\保密检查与监督\\document\\文档\\啊啊啊啊啊\\1.docx";

        String buffer = "";

        if (path.endsWith(".doc")) {
            InputStream is = new FileInputStream(new File(path));
            WordExtractor ex = new WordExtractor(is);
            buffer = ex.getText();
        } else if (path.endsWith(".docx")) {


            OPCPackage opcPackage = POIXMLDocument.openPackage(path);
            POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
            buffer = extractor.getText();

        }


        System.out.println(buffer);

        FileWriter fw = new FileWriter("E:\\.学习\\2022秋季学期\\保密检查与监督\\document\\文档\\啊啊啊啊啊\\test.txt");
        fw.write(buffer);
        fw.close();
        //ReadTxt.read();

    }
}
